<?php
namespace app\index\controller;
use app\common\controller\Base;
use think\Db;

class Show extends Base
{
    public function _initialize() {
        parent::_initialize();
        $start = array(
	            'user_all'      =>$this->user_all,
	            'app_down' =>$this->app_down,
	            'logo'           =>$this->logo
	    );
        $this->assign($start);
    }

    /**
     * @Purpose 电脑版帮助中心
     * @Time 2017-11
     */
    public function help()
    {
       //彩票种类列表
	    $lottery_type = $this->lotteryTypeList();
	    //电脑版广告
	    $pc_ad = $this->ADForPC();

	    $this->assign($lottery_type);
	    $this->assign($pc_ad);
        return $this->fetch();
    }

    /**
     * @Purpose 电脑版优惠活动
     * @Time 2017-11
     */
    public function favourable()
    {
        //彩票种类列表
	    $lottery_type = $this->lotteryTypeList();
	    //电脑版广告
	    $pc_ad = $this->ADForPC();
        //优惠活动信息
	    $youhuilist = Db::name('xt_yhhd_list')->where('xianshi',1)->order('paixu','DESC')->select();

        $this->assign($lottery_type);
        $this->assign($pc_ad);
        $this->assign('yhlist',$youhuilist);
        return $this->fetch();
    }

    /**
     * @Purpose 电脑版资讯信息
     * @Time 2017-11
     */
    public function newsList()
    {
        $page = input('get.page') ? input('get.page') : 1;
        $page_num = 20;
        //彩票种类列表
	    $lottery_type = $this->lotteryTypeList();
	    //电脑版广告
	    $pc_ad = $this->ADForPC();
        //总记录数
        $count = Db::name('xt_news')->where('xianshi',1)->count();
        //总页数
        $total_page = ceil($count / $page_num);
        if($page < 1) $page = 1;
        if($page > $total_page) $page = $total_page;
        //查询带分页的资讯信息
        $offset = ($page - 1) * $page_num;
        $new_list = Db::name('xt_news')->where('xianshi',1)->order('paixu','DESC')->limit($offset,$page_num)->select();
        foreach($new_list as &$v) {
            $v['fatime'] = date('Y-m-d H:i:s',$v['fatime']);
        }

        $this->assign($lottery_type);
        $this->assign($pc_ad);
        $this->assign('page',$page);
        $this->assign('ns_ls',$new_list);
        return $this->fetch('news_list');
    }

    /**
     * @Purpose 电脑版资讯详情
     * @Time 2017-11
     */
    public function newsDetail()
    {
        $nid = input('get.nid') ? input('get.nid') : 0;
        if($nid > 0) {
            $uis = Db::name('xt_news')->where('id',$nid)->find();
        }
        //彩票种类列表
        $lottery_type = $this->lotteryTypeList();
        //电脑版广告
        $pc_ad = $this->ADForPC();

        $this->assign($lottery_type);
        $this->assign($pc_ad);
        $this->assign('uis',$uis);
        return $this->fetch('news_detail');
    }

    /**
     * @Purpose 电脑版玩法介绍
     * @Time 2017-11
     */
    public function playWay()
    {
        $czid_wf = input('get.czid_wf') ? input('get.czid_wf') : 1;
        //判断彩种是否开启
        if($this->lottery_if_open($czid_wf) != 1) {
            echo '<script>history.go(-1);</script>';exit;
        }
        
        //彩票种类列表
	    $lottery_type = $this->lotteryTypeList();
	    //电脑版广告
	    $pc_ad = $this->ADForPC();
        //获取彩票玩法介绍
        $czkjlst = Db::name('caipai_list')->where('cp_if_open','<',2)->order('cp_dn_px','DESC')->select();
		if($czid_wf < 1) $czid_wf = 1;
		$wanfalist = Db::name('play_func')->where('czid',$czid_wf)->select();
		//获取彩种图标和名称
		$caizhong = Db::name('caipai_list')->where(['cp_if_open'=>['<',2],'id'=>$czid_wf])->find();

		$this->assign('cp',$caizhong);
		$this->assign($lottery_type);
		$this->assign($pc_ad);
		$this->assign('kj_list',$czkjlst);
		$this->assign('czid_wf',$czid_wf);
		$this->assign('wflist',$wanfalist);
        return $this->fetch('play_way');
    }

    /**
     * @Purpose 电脑版系统公告
     * @Time 2017-11
     */
    public function aboutList()
    {
		
        $page = input('get.page') ? input('get.page') : 1;
        $page_num = 20;
        //彩票种类列表
	    $lottery_type = $this->lotteryTypeList();
	    //电脑版广告
	    $pc_ad = $this->ADForPC();
        //总记录数
        $count = Db::name('xt_gonggao')->where('xianshi',1)->count();
      
		//总页数
        $total_page = ceil($count / $page_num);
        if($page < 1) $page = 1;
        if($page > $total_page) $page = $total_page;
        //查询带分页的公告信息
        $offset = ($page - 1) * $page_num;
        
		  
		$about_list = Db::name('xt_gonggao')->where('xianshi',1)->order('paixu','DESC')->limit($offset,$page_num)->select();
        
		foreach($about_list as &$v) {
            $v['fatime'] = @date('Y-m-d H:i:s',$v['fatime']);
			
        }

        $this->assign($lottery_type);
        $this->assign($pc_ad);
        $this->assign('page',$page);
        $this->assign('ns_ls',$about_list);
        return $this->fetch('about_list');
    }

    /**
     * @Purpose 电脑版公告详情
     * @Time 2017-11
     */
    public function aboutDetail()
    {
        $nid = input('get.nid') ? input('get.nid') : 0;
        if($nid > 0) {
            //公告详情信息
            $uis = Db::name('xt_gonggao')->where('id',$nid)->find();
        }
        //彩票种类列表
        $lottery_type = $this->lotteryTypeList();
        //电脑版广告
        $pc_ad = $this->ADForPC();

        $this->assign($lottery_type);
        $this->assign($pc_ad);
        $this->assign('uis',$uis);
        return $this->fetch('about_detail');
    }

    /**
     * @Purpose 电脑版活动大厅
     * @Time 2017-11
     */
    public function activity()
    {
        //彩票种类列表
	    $lottery_type = $this->lotteryTypeList();
	    //电脑版广告
	    $pc_ad = $this->ADForPC();
        //活动大厅信息
        $duquhjud = Db::name('xt_zzhd')->where('ifopen','<',2)->select();
        $i = 0;
        
        foreach ($duquhjud as &$item){
        	$item['tj_czje'] = explode('-', $item['tj_czje']);
        	$item['tj_tzje'] = explode('-', $item['tj_tzje']);
        	$item['hd_je'] = explode('-', $item['hd_je']);
        	$i = count($item['hd_je']);
        	for($q=0;$q<$i;$q++){
        		$item['sur'][]=[$item['tj_czje'][$q],$item['tj_tzje'][$q],$item['hd_je'][$q]];
        	}
        		
        }
        $this->assign($lottery_type);
        $this->assign($pc_ad);
        $this->assign('huodongxx',$duquhjud);
        return $this->fetch();
    }

    /**
     * @Purpose 电脑版手机购彩展示页面
     * @Time 2017-11
     */
    public function mobile()
    {
        //彩票种类列表
	    $lottery_type = $this->lotteryTypeList();
	    //电脑版广告
	    $pc_ad = $this->ADForPC();

	    $this->assign($lottery_type);
	    $this->assign($pc_ad);
        return $this->fetch();
    }

}
